<?php

class AuthorsController extends Zend_Controller_Action{
    public function init(){

    }

    public function indexAction(){
        $filterAuthors = new Application_Form_FilterAuthor();
        $filterAuthors->isValid($this->getRequest()->getParams());

        $authorsPaginator = Application_Model_Authors::getInstance()
            ->getPaginatorForFilter($filterAuthors->getValues());
        $authorsPaginator->setItemCountPerPage(12);
        $page = $this->getRequest()->getParam('page');
        if(!is_null($page)){
            $authorsPaginator->setCurrentPageNumber($page);
        }
        $this->view->filterAuthors = $filterAuthors;
        $this->view->filterParams = $this->getRequest()->getParams();
        $this->view->authorsPaginator = $authorsPaginator;
    }

    public function addAction(){

        $formAuthor = new Application_Form_Author();
        $request = $this->getRequest();
        if($request->isPost()){
            if($formAuthor->isValid($request->getPost())){
                Application_Model_Authors::getInstance()->create($formAuthor->getValues());
                $this->redirect($this->view->url(array('controller' => 'authors'), null, true));
            }
        }
        $this->view->formAuthor = $formAuthor;
    }

}

